$(function () {
  $('form').on('submit', function (e) {
    e.preventDefault()
    const username = $('[name=username]').val().trim()
    const password = $('[name=password]').val().trim()
    const phone = $('[name=phone]').val().trim()
    const sex = $('[name=sex]').val().trim()
    const vip = $('[name=vip]').val().trim()
    const question = $('[name=question]').val().trim()
    const answer = $('[name=answer]').val().trim()
    console.log(username, password, phone, sex, vip, question, answer);

    //const data = $(this).serialize()

    $.ajax({
      type: 'POST',
      url: 'http://124.223.14.236:3001/api/user/reg',
      data: {
        username,
        password,
        phone,
        sex,
        description: '',
        vip,
        question,
        answer,
      },
      // data,
      success(res) {
        console.log(res);
        if (!res.success) return console.log(res.msg);
        alert('账号注册成功')
        location.href = '/01-loginBaseCode/login.html'

      }
    })
  })
})